<?php
class Application_Model_SyllabusMapper{
	protected $_dbTable;

	public function setDbTable($dbTable){
		if (is_string($dbTable)) {
			$dbTable = new $dbTable();
		}
		if (!$dbTable instanceof Zend_Db_Table_Abstract) {
			throw new Exception('Invalid table data gateway provided');
		}
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable) {
			$this->setDbTable('Application_Model_DbTable_Syllabus');
		}
		return $this->_dbTable;
	}
	public function fetchByGroup($annee, $section){
		$resultSet = $this->getDbTable()->fetchByGroup($annee, $section);
		$entries = array();
		foreach ($resultSet as $row) {
			$entry = new Application_Model_Syllabus();
			$entry	->setSyllabusId($row->syllabus_id)
					->setIntitule(ucfirst($row->intitule))
					->setSection($row->libelle)
					->setAnnee($row->annee)
					->setNbPage($row->nb_page)
					->setAuteur(ucfirst($row->prenom).' '.ucfirst($row->nom))
					->setRelie(true)
					->setLivre(false);
			$entries[]=$entry;
		}
		return $entries;
	}
}